package d.day9;
import java.io.BufferedOutputStream;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class MinaApp  {

	public static void main(String[] args) {
		// D:\\long.long
		String path="C:/Users/SYZX/Desktop/1163.html";
		File file = new File(path);
		if (file.exists()&&file.isFile()) {
			// main
			FileInputStream fileInputStream = null;
			try {
				FileInputStream fileinputs = new FileInputStream(file);
				InputStreamReader inputStreamReader = new InputStreamReader(
						fileinputs);
				BufferedReader bufferedReader = new BufferedReader(inputStreamReader); 
				try {
					//bufferedReader.readLine();
					System.out.println("bufferedReader.readLine()");
					String line=null;
					
					//g:\\ips.txt
					File ipFile=new File("G:\\temp\\zx.txt");
					if(!ipFile.exists())
					{
						ipFile.createNewFile();
					}
					
					FileOutputStream fileOutputStream= new FileOutputStream(ipFile);
					while((line=bufferedReader.readLine())!=null)
					{
						System.out.println(MinaApp.getStr(line));	
					
						//BufferedOutputStream bufferedOutputStream=new BufferedOutputStream(fileOutputStream);
						//bufferedOutputStream.
						if(MinaApp.getStr(line)==null)
						{
							continue;
						}
						else
						{
							System.out.println(MinaApp.getStr(line)+"-------------测试------------------");
							fileOutputStream.write(MinaApp.getStr(line).getBytes());
							fileOutputStream.write("\r\n".getBytes());
						}				
						
					}
					fileOutputStream.flush();
					fileOutputStream.close();
				} catch (IOException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
			} catch (FileNotFoundException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}

		} else {
			System.out.println("not a file or no exist");
		}
		System.out.println("end");
	}
	
	/*
	* 从一串文字中提取一个IP
	*@paran content 待处理的一串文字
	*@return
	*/
	public static String getStr(String content){
		String regUrl ="[\u4e00-\u9fa5]+";// 中文
		//
        Pattern p = Pattern.compile(regUrl, Pattern.CASE_INSENSITIVE);
        Matcher m = p.matcher(content);
        boolean blnp = m.find();
        if(blnp==true)
        {//get it
        	return m.group();
        }
		return null;
		}
}